//
//  AppDelegate.m
//  NeteaseNews
//
//  Created by liutaifeng on 16/4/13.
//  Copyright © 2016年 liutaifeng. All rights reserved.
//

#import "AppDelegate.h"
#import "NewsViewController.h"
#import "ReadViewController.h"
#import "VideoViewController.h"
#import "TopicViewController.h"
#import "MyViewController.h"
#import "IsNight.h"
#import "LinkPageViewController.h"
@interface AppDelegate ()
<
 LinkPageViewControllerDelegate
>
@property (nonatomic, retain) UITabBarController *tabbar;
@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    _window.backgroundColor = [UIColor whiteColor];
    [_window makeKeyAndVisible];
    [_window release];
    //新闻界面
    NewsViewController *newsVC = [[NewsViewController alloc] init];
    UINavigationController *newsNAVC = [[UINavigationController alloc] initWithRootViewController:newsVC];
    //设置图片
    newsNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"新闻" image:[UIImage imageNamed:@"xinwen.png"] selectedImage:[UIImage imageNamed:@"xinwen1.png"]];
    
    
    //阅读界面
    ReadViewController *readVC = [[ReadViewController alloc] init];
    UINavigationController *readNAVC = [[UINavigationController alloc] initWithRootViewController:readVC];
    //设置图片
    readNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"阅读" image:[UIImage imageNamed:@"yuedu.png"] selectedImage:[UIImage imageNamed:@"yuedu1.png"]];
    
    //视频界面
    VideoViewController *videoVC = [[VideoViewController alloc] init];
    UINavigationController *videoNAVC = [[UINavigationController alloc] initWithRootViewController:videoVC];
    //设置图片
    videoNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"视频" image:[UIImage imageNamed:@"shipin.png"] selectedImage:[UIImage imageNamed:@"shipin1.png"]];
    
    
    //话题界面
    TopicViewController *topicVC = [[TopicViewController alloc] init];
    UINavigationController *topicNAVC = [[UINavigationController alloc] initWithRootViewController:topicVC];
    //设置图片
    topicNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"话题" image:[UIImage imageNamed:@"huati.png"] selectedImage:[UIImage imageNamed:@"huati1.png"]];
    
    //"我"界面
    MyViewController *myVC = [[MyViewController alloc] init];
    UINavigationController *myNAVC = [[UINavigationController alloc] initWithRootViewController:myVC];
    //设置图片
    myNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我" image:[UIImage imageNamed:@"wo.png"] selectedImage:[UIImage imageNamed:@"wo1.png"]];
    
    //设置tabbar
    self.tabbar = [[UITabBarController alloc] init];
    _tabbar.viewControllers = @[newsNAVC, readNAVC, videoNAVC, topicNAVC, myNAVC];

    _tabbar.tabBar.tintColor = [UIColor redColor];
    _tabbar.tabBar.translucent = NO;
    
    LinkPageViewController *linkPageVC = [[LinkPageViewController alloc] init];
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    if (![user boolForKey:@"fi"]) {
        self.window.rootViewController = linkPageVC;
        linkPageVC.delegate = self;
    } else {
        self.window.rootViewController = _tabbar;
    }

    return YES;
}
- (void)change {
     self.window.rootViewController = _tabbar;
}
//内存管理
- (void)dealloc
{
    [_window release];
    [super dealloc];
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
